package main

import (
	"encoding/json"
	"fmt"
	"gitee.com/wcs2/common/enums"
	"gitee.com/wcs2/common/enums/site"
	"gitee.com/wcs2/common/enums/task"
	"gitee.com/wcs2/common/enums/tl"
	"gitee.com/wcs2/common/models/wcs"
	"gitee.com/wcs2/common/utils/empty"
	"gitee.com/wcs2/common/utils/g"
	"gitee.com/wcs2/common/utils/ginhelper"
	"github.com/imroc/biu"
	"runtime"
	"strconv"
)

func main() {
	siteType := site.SiteInfoEnum(site.STORAGE)
	fmt.Println(siteType)
	fmt.Println(siteType.Value(site.STORAGE))

	taskTypeEnum := task.TaskStatusEnum.WAITING_TRANSFER
	fmt.Println(taskTypeEnum)

	none := task.RunModeEnum.NONE
	fmt.Println(task.RunModeEnum.IN + " | " + none)
	fmt.Println(task.GetRunModeDesc(task.RunModeEnum.MOVE))

	fmt.Println(tl.TlPositionEnum.ENTRANCE.Code + " | " + tl.TlPositionEnum.ENTRANCE.Des + " | " + tl.TlPositionEnum.ENTRANCE.PlcCode.(string))

	out := fmt.Sprintf("%s | %s | %d", tl.TlLreqStatusEnum.NORMAL.Code, tl.TlLreqStatusEnum.NORMAL.Des, tl.TlLreqStatusEnum.NORMAL.PlcCode)
	fmt.Println(out)

	test(tl.TlActionTypeEnum.AGV_LOAD)

	var pp enums.PositionEnum

	if pp == (enums.PositionEnum{}) {
		fmt.Println("空指针")
	} else {
		fmt.Println(pp)
	}

	var z enums.PositionStruct
	z = tl.TlActionTypeEnum.AGV_LOAD
	if z == (enums.PositionStruct{}) {
		fmt.Println("空指针")
	} else {
		fmt.Println(z)
	}

	boxReqNum := do()
	fmt.Println(boxReqNum)

	actor := testStruct()
	fmt.Println(actor.ActorId + " | " + actor.TaskId)

	var num int
	fmt.Println(empty.IsEmpty(num))

	fmt.Println(g.Int(tl.TlPositionEnum.ENTRANCE.PlcCode))

	chars := []byte("P00000001")
	var result string
	for i, char := range chars {
		if i%2 > 0 {
			continue
		}
		a := fmt.Sprintf("%04s", biu.ToBinaryString(char))
		var b string
		if i < (len(chars) - 1) {
			b = fmt.Sprintf("%04s", biu.ToBinaryString(chars[i+1]))
		}
		s, _ := strconv.ParseInt(a+b, 2, 64)
		result += "," + fmt.Sprintf("%d", s)
	}
	fmt.Println(result)

	var num1 int
	num1 = 12
	fmt.Println(num1)

	params := make(map[string]interface{})
	tt := []string{"a", "b"}
	params["locations"] = tt
	params["taskNo"] = "2021031919098881"
	p, _ := json.Marshal(params)
	fmt.Println(string(p))
	ps, _ := json.Marshal(params)
	task := &wcs.BizOfsTask{
		InitData: ps,
		ExtData:  ps,
	}

	m := task.GetExtDataMap()
	ps, _ = json.Marshal(m)
	fmt.Printf("输出：%s \n", string(ps))

	var p2 map[string]interface{}

	json.Unmarshal(task.InitData, &p2)

	fmt.Println(p2)

	putaway := new(int)
	*putaway = 1
	picking := 1

	fmt.Println(*putaway)
	fmt.Println(&picking)
	tprintln(&picking)

	var count = 0
	count++
	fmt.Printf("***: %d \n", count)

	fmt.Println(runtime.GOOS)
	fmt.Println(runtime.GOARCH)

	r := &ginhelper.RestResult{}
	r = r.BuildFailedResultMsg("输出")

	pa, _ := json.Marshal(*r)
	fmt.Println(string(pa))

	taskCode := "6791192883576700928"
	fmt.Print(g.Pos(taskCode, "_"))

	subTaskCode := g.Split(taskCode, "_")

	fmt.Println(subTaskCode)

	var sss string
	fmt.Println(sss == "")
}

func test(p enums.PositionStruct) {
	fmt.Println(p.Code + " | " + p.Des)
}
func tprintln(picking *int) {
	fmt.Println(*picking)
}
func do() *int {
	var boxReqNum int
	boxReqNum = 12
	return &boxReqNum
}

func testStruct() *wcs.WfTaskActor {
	var actor wcs.WfTaskActor
	actor.TaskId = "1"
	actor.ActorId = "111222222"
	return &actor
}
